package com.simple.editor.converter;

import com.simple.editor.ui.FileModel;
import com.simple.editor.vcs.VcsFile;
import com.simple.editor.vcs.VcsFileImpl;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: vsoroka
 * Date: 01.07.13
 * Time: 11:30
 * To change this template use File | Settings | File Templates.
 */
public class FileModelConverter {

    private FileModelConverter() {
    }

    public static Map<String, VcsFile> convertFiles(final FileModel... files) {
        final Map<String, VcsFile> vcsFilesMap = new HashMap<String, VcsFile>(files.length);
        for (final FileModel file : files) {
            VcsFile vcsFile = convert(file);
            if (vcsFile != null) {
                vcsFilesMap.put(vcsFile.getPath(), vcsFile);
            }
        }
        return Collections.unmodifiableMap(vcsFilesMap);
    }

    public static VcsFile convert(final FileModel file) {
        final VcsFile vcsFile = file != null ? new VcsFileImpl(file.getAbsolutePath()) : null;
        return vcsFile;
    }
}
